package com.zjkj.mp.dao.channel.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zjkj.mp.dao.DaoBase;
import com.zjkj.mp.dao.channel.ChannelDao;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.vo.channel.MpChannel;

@Repository
public class ChannelDaoImpl extends DaoBase implements ChannelDao {

	@SuppressWarnings("unchecked")
	public List<MpChannel> getMpChannelList(int tdId) {
		List<MpChannel> list = getSqlMapClient().queryForList("get.channelList", tdId);
		return list;
	}

	public int insertMpChannel(MpChannel channel) {
		int num = getSqlMapClient().update("ins.insertChannel", channel);
		return num;
	}

	public int delMpChannel(int tdId) {
		int num = getSqlMapClient().delete("del.delMpChannel", tdId);
		return num;
	}

	public int updMpChannel(MpChannel channel) {
		int num = getSqlMapClient().update("upd.updMpChannel", channel);
		return num;
	}

	@SuppressWarnings("unchecked")
	public List<MpChannel> getMpChannelList() {
		List<MpChannel> list = getSqlMapClient().queryForList("get.channelAllList");
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public PaginatedResult getMpChannelPageList(int nowPage, int maxRow, Map<String, Object> map) {
		if(map == null) 
			map= new HashMap<String, Object>();
		
		PaginatedResult result = new PaginatedResult(nowPage, maxRow);
		List<MpChannel> channel =  this.getSqlMapClient().queryForList("get.channelPageList", map, (nowPage-1)*maxRow, maxRow);
		result.setResult(channel);
 
		int count = ((Integer)this.getSqlMapClient().queryForObject("get.channelPageListCount",map)).intValue();
		result.setTotalSize(count);
		
		return result;
	}

	public int flagChannel(Map<String, Object> map) {
		int num = getSqlMapClient().update("upd.flagChannel", map);
		return num;
	}
	
	@SuppressWarnings("unchecked")
	public List<MpChannel> getMpChannelListStart(int tdzt){
		List<MpChannel> list = getSqlMapClient().queryForList("get.channelListStart", tdzt);
		return list;
	}

}
